package com.upic.serviceImpl;

import com.upic.po.jurisdiction.Resource;
import com.upic.repository.ResourceRepository;
import com.upic.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhubuqing on 2018/2/7.
 */
@Service("resourceService")
public class ResourceServiceImpl implements ResourceService {
    @Autowired
    private ResourceRepository resourceRepository;

    @Override
    public Resource saveResource(Resource resource) {
        return resourceRepository.save(resource);
    }

    @Override
    public String deleteResource(long resourceId) {
        resourceRepository.delete(resourceId);
        return "SUCCESS";
    }

    @Override
    public Page<Resource> searchResource(Pageable pageable) {
        return resourceRepository.findAll(pageable);
    }

    @Override
    public List<Resource> searchResource() {
        return resourceRepository.findAll();
    }

    @Override
    public Resource findOne(long resourceId) {
        return resourceRepository.findOne(resourceId);
    }

    @Override
    public Resource updateResource(Resource resource) {
        return resourceRepository.saveAndFlush(resource);
    }
}
